#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,a[N];
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
	int T;
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
			cin>>a[i];
		int ans=0;
		for(int i=0;i<1<<n;i++)
		{
			int cnt=0,c1=0,c2=0;
			for(int j=1;j<=n;j++)
			{
				if(i&1<<(j-1))
				{
					if(c1==a[j])cnt+=a[j];
					c1=a[j];
				}
				else
				{
					if(c2==a[j])cnt+=a[j];
					c2=a[j];
				}
			}
			if(ans<cnt)ans=cnt;
		}
		cout<<ans<<endl;
	}
    return 0;
}
